package com.qf.controller;

import com.qf.pojo.DtsOrder;
import com.qf.pojo.DtsOrderGoods;
import com.qf.service.DtsOrderGoodsService;
import com.qf.service.DtsOrderService;
import com.qf.service.DtsUserService;
import com.qf.util.ResponseUtil;
import com.qf.vo.StatGoodsVo;
import com.qf.vo.StatOrderVo;
import com.qf.vo.StatUserVo;
import com.qf.vo.StatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Zwnan
 */
@RestController
@RequestMapping("/admin/stat")
@CrossOrigin
public class StatController {

    private static final int STATIS_DAYS_RANG= 30;
    @Autowired
    private DtsUserService dtsUserService;

    @Autowired
    private DtsOrderGoodsService dtsOrderGoodsService;

    @GetMapping("/user")
    public Object userList(){
        List<StatUserVo> statUserVoList = dtsUserService.findstatUser(STATIS_DAYS_RANG);

        Map map=new HashMap();
        String []strings={"day","users"};
        map.put("rows", statUserVoList);
        map.put("columns", strings);

        return ResponseUtil.ok(map);
    }

    @Autowired
    private DtsOrderService dtsOrderService;

    @GetMapping("/order")
    public Object orderList(){

        List<StatOrderVo> statOrderVoList =dtsOrderService.findstatOrder();

        String[] strings = {"day",
                "orders",
                "customers",
                "amount",
                "pcr"};
        Map map = new HashMap();
        map.put("columns",strings);
        map.put("rows", statOrderVoList);

        return ResponseUtil.ok(map);
    }

    @GetMapping("/goods")
    public Object goodsList(){

        List<StatGoodsVo> statGoodsVos =dtsOrderGoodsService.findstatGoods();

        String[] strings = {"day",
                "orders",
                "products",
                "amount"};
        Map map = new HashMap();
        map.put("columns",strings);
        map.put("rows", statGoodsVos);

        return ResponseUtil.ok(map);
    }


}
